package com.fkdx.webman.config;

import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;


import java.util.ArrayList;
import java.util.List;

/**
 * @author wangtengfei
 */
@Configuration
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        ParameterBuilder aParameterBuilder = new ParameterBuilder();
        aParameterBuilder.name("accessToken").defaultValue("eyJhbGciOiJIUzI1NiJ9.eyJhY2Nlc3NUb2tlbiI6IntcImlkXCI6MSxcIm5hbWVcIjpcIua1i-ivlVwiLFwidXNlcm5hbWVcIjpcInJvb3RcIixcInRlbmFudElkXCI6MX0iLCJzdWIiOiJyb290IiwiZXhwIjoxNjg4MzQ0MzM4fQ.b_JfnbYy_atWXGeVnYOu4n8s8dQZjg7mTZrB5D8a2xA").description("token").modelRef(new ModelRef("string")).parameterType("header").required(true).build();

        List<Parameter> aParameters = new ArrayList<>();
        //ApiInfo apiInfo = new ApiInfo();
        aParameters.add(aParameterBuilder.build());
        return new Docket(DocumentationType.SWAGGER_2)
                .globalOperationParameters(aParameters)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.fkdx.webman.controller"))
                .paths(PathSelectors.any()).build();
    }
}
